import javax.servlet.AsyncContext;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.io.IOException;


public class UserService implements Runnable{

    private AsyncContext asyncContext;

    public UserService(AsyncContext asyncContext) {
        this.asyncContext = asyncContext;
    }

    @Override
    public void run() {
        ServletRequest request = asyncContext.getRequest();
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        String name = request.getParameter("name");
        System.err.println(name);
        ServletResponse response = asyncContext.getResponse();
        try {
            response.getWriter().write("nihao");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        asyncContext.complete();
    }
}
